package main.collection;

import com.google.gson.Gson;
import main.common.Bird;
import org.junit.Test;

import java.util.*;

/**
 * Created by ChengGM on 2016/12/9.
 */
public class SetTest {
    //set存值
    @Test
    public void SetTest(){
        Set<Integer> st = new HashSet<Integer>();
        Random rand = new Random();
        for(int i=0;i<10;i++){
            int l =rand.nextInt(50);
            System.out.print(l+"--> ");
            st.add(l);
        }
        System.out.println();
        for(Integer i :st) {
            System.out.print(i+"==>");
        }
    }
    //set排序
    @Test
    public void SetSortTest(){
        Set<Integer> st = new TreeSet<Integer>();
        Random rand = new Random();
        for(int i=0;i<10;i++){
            int l =rand.nextInt(50);
            System.out.print(l+"--> ");
            st.add(l);
        }
        System.out.println();
        for(Integer i :st) {
            System.out.print(i+"==>");
        }
    }
    @Test
    public void test() throws Exception{
        List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("1");
        HashSet set = new HashSet();
        set.addAll(list);
        System.out.println(new Gson().toJson(set));
    }

    @Test
    public void test2() throws Exception{
        main.common.Bird brid = new Bird();
        brid.setName("张三");
        brid.setAge(20);
        main.common.Bird brid2 = new Bird();
        brid2.setName("张三");
        brid2.setAge(20);
        main.common.Bird brid3 = new Bird();
        brid3.setName("张三");
        brid3.setAge(20);
        List<Bird> list = new ArrayList<Bird>();
        list.add(brid);
        list.add(brid2);
        list.add(brid3);
        Set set = new HashSet();
        set.addAll(list);
        System.out.println(new Gson().toJson(set));


    }


}


